package fr.afcepf.vod.metier;

import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import fr.afcepf.vod.dao.IDaoTag;
import fr.afcepf.vod.entities.Tag;
import fr.afcepf.vod.entities.Video;
@Named
public class GestionTagImpl implements IGestionTag {
	
	private IDaoTag daoTag;
	
	public IDaoTag getDaoTag() {
		return daoTag;
	}
	@Inject
	public void setDaoTag(IDaoTag daoTag) {
		this.daoTag = daoTag;
	}

	@Override
	public List<Tag> getListeTags() {
		return daoTag.getListeTags();
	}

	@Override
	public String getLabel(Tag t) {
		if(t.getDescription() != null){
			System.out.println("Coucou");
			return t.getDescription().getIntitule();
		}
		return null;
	}

	@Override
	public int getStrength(Tag t) {
		int maxOccurences = daoTag.getMaxOccurences();
		int occurences = t.getNbOccurencesRecherche();
		int strength = (int) (5 * occurences / maxOccurences);
		if(strength < 5){
			strength++;
		}
		return strength;
	}
	@Override
	public List<Video> getVideosByTagMessage(String message) {
		Tag tag = daoTag.getTagByMessage(message);
		tag.setNbOccurencesRecherche(tag.getNbOccurencesRecherche() + 1);
		daoTag.updateTag(tag);
		return daoTag.getVideosByTagMessage(message);
	}

}
